package helpers.preloaders
{  
	import flash.display.Loader;  
	import flash.events.Event;  
	import flash.events.TimerEvent;  
	import flash.geom.Point;  
	import flash.utils.ByteArray;  
	import flash.utils.Timer;  
	
	public class WelcomeScreen extends Loader  
	{  
		
		[Embed(source="images/binds/loading1.swf", mimeType="application/octet-stream")]  
		public var WelcomeScreenGraphic : Class;  
		public var timer : Timer;  
		private var fadeInRate : Number  = .05;  
		private var timeAutoClose : int = 100;  
		public var ready : Boolean = false;   
		public var COMPLETE_EVENT : String = "complete";  
		private var completeFlag : Boolean = true;  
		
		
		public function WelcomeScreen()  
		{  
			this.visible = false;  
			this.alpha = 0;  
			timer = new Timer(1);  
			timer.addEventListener(TimerEvent.TIMER, updateView);  
			timer.start();  
			this.loadBytes(new WelcomeScreenGraphic() as ByteArray);  
		}  
		
		public function updateView(event : TimerEvent):void  
		{
			if(this.alpha < 1)
				this.alpha = this.alpha + this.fadeInRate;  
			if(completeFlag)  
			{
				this.stage.addChild(this);  
				var point : Point = new Point();  
				this.x = this.stage.stageWidth/2 - 270;  
				this.y = this.stage.stageHeight/2 - 148;          
				this.visible=true;  
				completeFlag  = false;  
			}  
			if (this.ready && timer.currentCount > this.timeAutoClose)  
				closeScreen();  
		}  
		
		public function closeScreen():void  
		{  
			timer.removeEventListener(TimerEvent.TIMER, updateView);  
			timer.addEventListener(TimerEvent.TIMER, closeScreenFade);                      
		}  
		
		public function closeScreenFade(event : TimerEvent):void  
		{  
			timer.stop();  
			this.parent.removeChild(this);  
			dispatchEvent(new Event(COMPLETE_EVENT));  
		}          
	}   
}  